import request from '@/utils/request'

// 资讯分页查询
export async function GetNews(params) {
  const { list, pageIndex, totalCount } = await request({
    url: '/News/GetNews',
    method: 'post',
    params
  })
  if (list.length > 0) {
    list.forEach(item => {
      item.picurl = item.picurl.split(',')
      item.headpic = item.picurl[0]
    })
  }
  return {
    list,
    pageIndex,
    totalCount
  }
}

// 资讯
export async function FirstNews(params) {
  const { data } = await request({
    url: '/News/FirstNews',
    method: 'post',
    params
  })
  if (data) {
    data.picurl = data.picurl.split(',')
    data.headpic = data.picurl[0]
  }
  return data
}

// 资讯 新增、修改
export async function AddEditNews(data) {
  const res = await request({
    url: '/News/AddEditNews',
    method: 'post',
    data
  })
  return res
}

// 资讯 删除
export async function DeleteNews(data) {
  const res = await request({
    url: '/News/DeleteNews',
    method: 'post',
    data
  })
  return res
}

// 启用，停用 资讯
export async function SetState(params) {
  const res = await request({
    url: '/News/SetState',
    method: 'post',
    params
  })
  return res
}

// 分类 分页查询
export async function GetTypes(params) {
  const res = await request({
    url: '/News/GetTypes',
    method: 'post',
    params
  })
  return res
}

// 分类 新增、修改
export async function AddEditType(data) {
  const res = await request({
    url: '/News/AddEditType',
    method: 'post',
    data
  })
  return res
}

// 分类 删除
export async function DeleteType(data) {
  const res = await request({
    url: '/News/DeleteType',
    method: 'post',
    data
  })
  return res
}
